﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;
using University.Workshop.Model;

namespace University.Workshop.Presenters
{
    public class RegistrationRentPresenter
    {
        private IRent View;
        public RegistrationRentPresenter(IRent view){ View = view; }

        public string OnAddAnAmountToList()
        {
            if (string.IsNullOrEmpty(View.Amount) || string.IsNullOrWhiteSpace(View.Amount))
                return "Ingrese un monto...";
            if (string.IsNullOrEmpty(View.Note) || string.IsNullOrWhiteSpace(View.Note))
                return "Ingrese una nota del monto...";
            return "Todo esta bien";
        }

        public string OnRegisterRent()
        {
            if (string.IsNullOrEmpty(this.View.RentCode) || string.IsNullOrEmpty(this.View.Concept) || string.IsNullOrEmpty(this.View.Category))
                return "Falta llenar campos obligatorios!";

            if (this.View.TotalAmount == "0")
                return "No hay ningun producto en la lista de venta!";

            Rent rent = new Rent();
            rent.CodeRent = this.View.RentCode;
            rent.CodeUser = this.View.UserCode;
            rent.CurrentDate = this.View.DateRent;
            rent.Concept = this.View.Concept;
            rent.Category = this.View.Category;
            rent.TotalAmount = this.View.TotalAmount;
            RentController.RentRegister(rent);
            for (int i = 0; i < this.View.ListOfAmounts.Count; i++)
            {
                RentController.RentDetailRegister(this.View.ListOfAmounts[i]);
            }
            return "Registro exitoso!";
        }

        public bool OnInitializeFormGetRentCode()
        {
            string resp = RentController.GetRentCode();
            if(resp!="Error")
            {
                View.RentCode = resp;
                return true;
            }
            else
                return false;
        }
    }
}
